﻿using System;
using System.Diagnostics;
using IRUM.Utils;
using IRUM.XingAPI;

namespace IRUM.TR
{
    /// <summary>
    /// S3_ 
    /// 실시간 KOSPI 종목 체결정보 수신
    /// </summary>
    public class S3_ : CBaseReal
    {
        private string 단축코드 = String.Empty;

        public S3_(string 단축코드)
        {
            this.단축코드 = 단축코드;
            SetClassData(TR_Type.S3_);
        }

        //private void SetOutBlockData(실시간체결정보 체결정보)
        //{
        //    체결정보.체결시간 = IRUM_Utils.시간읽기(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "chetime"));
        //    체결정보.전일대비구분 = IRUM_Utils.전일대비구분읽기(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "sign"));
        //    체결정보.전일대비 = Convert.ToInt64(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "change"));
        //    체결정보.등락율 = Convert.ToDouble(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "drate"));
        //    체결정보.현재가 = Convert.ToInt64(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "price"));
        //    체결정보.체결구분 = IRUM_Utils.체결구분읽기(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "cgubun"));
        //    체결정보.체결량 = Convert.ToInt64(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "cvolume"));
        //    체결정보.누적거래량 = Convert.ToInt64(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "volume"));
        //    체결정보.누적거래대금 = Convert.ToInt64(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "value"));
        //    체결정보.매도누적체결량 = Convert.ToInt64(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "mdvolume"));
        //    체결정보.매도누적체결건수 = Convert.ToInt64(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "mdchecnt"));
        //    체결정보.매수누적체결량 = Convert.ToInt64(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "msvolume"));
        //    체결정보.매수누적체결건수 = Convert.ToInt64(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "mschecnt"));
        //    체결정보.체결강도 = Convert.ToDouble(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "cpower"));

        //    체결정보.매도호가 = Convert.ToInt64(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "offerho"));
        //    체결정보.매수호가 = Convert.ToInt64(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "bidho"));
        //    체결정보.전일동시간대거래량 = Convert.ToInt64(m_RealCtrl.m_Real.GetFieldData(OutBlockName, "jnilvolume"));

        //    체결정보.단축코드 = m_RealCtrl.m_Real.GetFieldData(OutBlockName, "shcode");
        //}

        public override void HandleQuery()
        {
            try
            {
                //실시간체결정보 정보 = new 실시간체결정보();

                //SetOutBlockData(정보);

                //Stock stock = SubForm.m_ControlTable[정보.단축코드] as Stock;
                //stock.AddData(RealType.실시간체결정보, 정보);
            }
            catch (Exception e)
            {
                Debug.Print(e.ToString());
            }
        }

        protected override void SetRequestData()
        {
            m_Real.SetFieldData(InBlockName, "shcode", 단축코드);
        }

        public void Cancel(string shcode)
        {
            m_Real.UnadviseRealDataWithKey(shcode);
        }

        public void Add(string shcode)
        {
            m_Real.SetFieldData(InBlockName, "shcode", shcode);
            m_Real.AdviseRealData();
        }
    }
}
